package com.chushouya.common.support;

import com.general.framework.core.utils.ThreadContext;

/**
 * 上下文操作
 * @author leejean team
 */
public class Contexts {

    /**
     * 请求头Key
     */
    public static final String REQUEST_HEADER_CONTEXT_KEY = "Contexts.RequestHeaderContext";

    /**
     * 用户上下文key
     */
    public static final String REQUEST_USER_CONTEXT_KEY = "Contexts.RequestUserContext";

    /**
     * 获取请求头数据
     */
    public static RequestHeaderContext getHeaderContext() {
        final RequestHeaderContext headerContext = (RequestHeaderContext) ThreadContext.getValue(REQUEST_HEADER_CONTEXT_KEY);
        if (headerContext == null) {
            return new RequestHeaderContext();
        }
        return headerContext;
    }

    /**
     * 获取用户上下文
     */
    public static RequestUserContext getUserContext() {
        final RequestUserContext userContext = (RequestUserContext) ThreadContext.getValue(REQUEST_USER_CONTEXT_KEY);
        if (userContext == null) {
            return new RequestUserContext();
        }
        return userContext;
    }
}
